<?php
namespace App\Models\Chain\Invite;


use App\Models\Factory\InviteFactory;
use App\Models\Chain\AbstractHandler;
use App\Models\Factory\UserInviteCodeFactory;


//更新用户邀请表

class UpdateUserInviteAction extends AbstractHandler
{
	private $params = array();
    protected $error = array('error' => '更新用户邀请日志表失败', 'code' => 7011);


    public function __construct($params)
	{
		$this->params = $params;
	}
	
	
	
	/**
	 *
	 * @return array|bool
	 */
	public function handleRequest()
	{
		if ($this->updateUserInvite($this->params) == true)
		{
			$this->setSuccessor(new CreateCreditAction($this->params));
			return $this->getSuccessor()->handleRequest();
		}
		else
		{
			return $this->error;
		}
	}


	/**
	 *更新邀请日志表
	 * @param $params
	 * @return bool
	 */
	private function updateUserInvite($params)
	{
	    //注册者手机号
        $userphone = $params['userphone'];
        //邀请人的id
        $user_id = $params['inviteCode'] - 1902;
       $result =  UserInviteCodeFactory::updateUserInviteLog($userphone,$user_id);
        if($result)
        {
            $params['integral'] = $result;
            $this -> params = $params;
            return true;
        }
	}
}
